<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            background: red;
            width: 200px;
            height: 200px;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <button id="btn">改变颜色</button>
    <script>
        var colors=["red", "blue", "yellow", "green", "black", "orange"];
        var oBtn=document.getElementById("btn");
        var oBox=document.getElementsByClassName("box")[0];

        oBtn.onclick=function(){
            var num=0;
            setInterval(function(){
                num++;
                if(num>5){
                    num=0;
                }
                oBox.style.backgroundColor=colors[num];
                document.body.style.backgroundColor=colors[num];
            }, 100);
        }
    </script>
</body>
</html>